package cate.game.rank.h;

import cate.common.table.d.GDForbidden;
import cate.game.GameBody;
import cate.game.rank.po.Rank;
import cate.game.role.Role;

import java.util.*;

public class ForbiddenRankHandlers {
    public final Map<Integer, ForbiddenRankHandler> handlers = new HashMap<>();

    public Collection<ForbiddenRankHandler> getHandlers() {
        return handlers.values();
    }

    public void initialize(GameBody game) {
        ForbiddenRankHandler handler0 = new ForbiddenRankHandler(GDForbidden.RANK_ALL_TYPE);
        handler0.initialize(game);
        handlers.put(GDForbidden.RANK_ALL_TYPE, handler0);

//        List<ForbiddenRoomRow> typeRows = game.table.forbidden.room.getList();
//        typeRows.forEach(e -> {
//            ForbiddenRankHandler handler = new ForbiddenRankHandler(e.id);
//            handler.initialize(game);
//            handlers.put(e.id, handler);
//        });
    }

    public void record(Role role, int type, int score, long time) {
        ForbiddenRankHandler handler = handlers.get(type);
        if (handler != null) {
            handler.record(role, score, time);
        }
    }

    public void updateRole(Role role) {
        handlers.values().forEach(e -> e.updateRole(role));
    }

    public List<Rank> getRankList(int type) {
        ForbiddenRankHandler handler = handlers.get(type);
        if (handler == null) {
            return new ArrayList<>();
        }
        return handler.getRankList(null);
    }

    public void forceSave() {
        handlers.values().forEach(RankHandler::forceSave);
    }

}
